package com.jsh.frame.myframe2.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bigkoo.svprogresshud.SVProgressHUD;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

import butterknife.ButterKnife;

/**
 * Created by Admin on 2016/7/26.
 * Fragment基类
 */
public abstract class BaseFragment extends Fragment {

    protected View rootView;
    public SVProgressHUD svProgressHUD;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = View.inflate(getActivity(), getResId(), null);
            ButterKnife.bind(this, rootView);
            Logger.addLogAdapter(new AndroidLogAdapter());//初始化日志工具
            svProgressHUD = new SVProgressHUD(getActivity());
        }
        return rootView;

    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }

    protected abstract int getResId();

    protected abstract void initView();

    protected abstract void initData();

//    public boolean showEmptToast(TextView editText, String tip) {
//        String s = editText.getText().toString();
//        if (StringUtil.isEmpty(s)) {
//            Toast.makeText(getActivity(), tip, Toast.LENGTH_SHORT).show();
//            return false;
//        } else {
//            return true;
//        }
//
//    }

    /**
     * 事件通知
     */
//    public void onEventMainThread(MessageEvent event) {
//    }

    /**
     * 点击事件通知
     */
//    public void onEventMainThread(ClickEvent event) {
//    }
    protected void showLoadingLabel() {
        showLoadingLabel("加载中...");
    }

    protected void showLoadingLabel(String msg) {
        svProgressHUD.showWithStatus(msg);
    }

    protected void dismissLoadingLabel() {
        if (svProgressHUD.isShowing()) {
            svProgressHUD.dismiss();
        }
    }

    /**
     * @return 布局文件id
     */


//    protected void initTitle(String title) {
//        this.initTitle(0, null, title, 0, null, 0);
//    }
//
//    protected void initTitle(String strleft, String strcenter) {
//        this.initTitle(0, strleft, strcenter, 0, null, 0);
//    }
//
//    protected void initTitle(int resleft, String strcenter) {
//        this.initTitle(resleft, null, strcenter, 0, null, 0);
//    }
//
//    protected void initTitle(int resleft, String strcenter, String strright) {
//        this.initTitle(resleft, null, strcenter, 0, strright, 0);
//    }
//
//    protected void initTitle(int resleft, String strcenter, int resright) {
//        this.initTitle(resleft, null, strcenter, 0, null, resright);
//    }

    /**
     * 设置头布局
     */
//    protected void initTitle(int resLeft, String strLeft, String strContent, int resContent, String strRight, int resRight) {
//
//        ImageView ivTitleLeft = (ImageView) rootView.findViewById(R.id.iv_topbar_left);
//        ImageView ivTitleRight = (ImageView) rootView.findViewById(R.id.iv_topbar_right);
//        TextView tvTitleLeft = (TextView) rootView.findViewById(R.id.tv_topbar_left);
//        TextView tvTitleContent = (TextView) rootView.findViewById(R.id.tv_topbar_center);
//        TextView tvTitleRight = (TextView) rootView.findViewById(R.id.tv_topbar_right);
//        ImageView ivTitleCenter = (ImageView) rootView.findViewById(R.id.iv_topbar_logo);
//
//        if (resLeft == 0) {
//            ivTitleLeft.setVisibility(View.GONE);
//        } else {
//            ivTitleLeft.setVisibility(View.VISIBLE);
//            ivTitleLeft.setImageResource(resLeft);
//            ivTitleLeft.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    onClickTitleLeft(v);
//                }
//            });
//        }
//        if (resRight == 0) {
//            ivTitleRight.setVisibility(View.GONE);
//        } else {
//            ivTitleRight.setVisibility(View.VISIBLE);
//            ivTitleRight.setImageResource(resRight);
//            ivTitleRight.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    onClickTitleRight(v);
//                }
//            });
//        }
//
//        if (resContent == 0) {
//            ivTitleCenter.setVisibility(View.GONE);
//        } else {
//            ivTitleCenter.setVisibility(View.VISIBLE);
//            ivTitleCenter.setImageResource(resContent);
//        }
//
//        if (strLeft == null) {
//            tvTitleLeft.setVisibility(View.GONE);
//        } else {
//            tvTitleLeft.setVisibility(View.VISIBLE);
//            tvTitleLeft.setText(strLeft);
//            tvTitleLeft.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    onClickTitleLeft(v);
//                }
//            });
//        }
////
//        if (strContent == null) {
//            tvTitleContent.setVisibility(View.GONE);
//        } else {
//            tvTitleContent.setVisibility(View.VISIBLE);
//            tvTitleContent.setText(strContent);
//        }
//
//        if (strRight == null) {
//            tvTitleRight.setVisibility(View.GONE);
//        } else {
//            tvTitleRight.setVisibility(View.VISIBLE);
//            tvTitleRight.setText(strRight);
//            tvTitleRight.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    onClickTitleRight(v);
//                }
//            });
//        }
//    }
    protected void onClickTitleLeft(View v) {
    }

    protected void onClickTitleRight(View v) {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
